import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';
import set_node_cls from '@feidao/web/atom/browser/ui/set-node-cls';
import fire_component_msg from '@feidao/web/atom/browser/fsm/fire-component-msg';
import doc_code from '@feidao/web/atom/browser/msg/doc-code';
import nodejs from '@feidao/web/atom/browser/msg/nodejs';

export default async function (fd: IFeidaoAiBrowserComponent, ...args: any[]) {
	console.log('确定');
	const form_add = fd.data.form_add;
	const can_submit = fd.data.can_submit;
	const cont_des = form_add.cont_des.value;
	if (!cont_des) {
		fire_component_msg('zj-common-002', 'ec-001', 'fail', '请录入内容描述');
		return;
	}
	const cont_address = form_add.cont_address.value;
	if (!cont_address) {
		fire_component_msg('zj-common-002', 'ec-001', 'fail', '请录入内容地址');
		return;
	}
	const cont_no = (await doc_code('xmedia', '12', 'f96b5510-8cd6-4100-9ac5-44f191a3a769', '')).result;
	if (can_submit) {
		fd.data.can_submit = false;
		const res = await nodejs("xmedia", "moxuan_add_h5_playback_content", { data: { cont_no, cont_des, cont_address } });
		if (res == "success") {
			fire_component_msg('zj-common-002', 'ec-001', 'success', '保存成功');
			fire_component_msg('ZJ201801270000000602', 'ME20180109000005');
			set_node_cls(fd.data.node, 'display-n', false);
			fd.data.can_submit = true;
		} else {
			fd.data.can_submit = true;
			fire_component_msg('zj-common-002', 'ec-001', 'fail', '提交失败');
		}
	}
}
